package com.me.web;

import com.me.pojo.Pokemon;
import com.me.service.PokemonService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/updatepokemonServlet")
public class updatepokomonServlet extends HttpServlet {
private PokemonService pokemonService = new PokemonService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //1.接受表单数据
        String pokemonid = request.getParameter("id");
        String pokemonname = request.getParameter("pokemonname");
        String pokemontype = request.getParameter("pokemontype");
        String pokemonskill = request.getParameter("pokemonskill");
        String pokemondescribe = request.getParameter("pokemondescribe");
        String pokemontime =request.getParameter("pokemontime");
        //2.封装成pokemon对象
        Pokemon pokemon = new Pokemon();
        pokemon.setId(Integer.valueOf(pokemonid));
        pokemon.setName(pokemonname);
        pokemon.setType(pokemontype);
        pokemon.setSkill(pokemonskill);
        pokemon.setDescribe(pokemondescribe);
        pokemon.setTime(pokemontime);
        //3.调用service保存到数据库
        pokemonService.updatepokemon(pokemon);
        //4.转发到宝可梦全图鉴
        request.getRequestDispatcher("/pokemonallServlet").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
